package com.test.one.springboottestpne.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.test.one.springboottestpne.entity.Role;
import com.test.one.springboottestpne.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * sjskjss
 */
@RestController
public class RoleController {

    @Autowired
    RoleService roleService;

    @RequestMapping(value = "/getRoleList",method = RequestMethod.GET)
    public Map<String,Object> getRoleList(Role role,Integer sEcho,Integer start,Integer length){
        PageHelper.startPage(start,length);
        List<Role> roles = roleService.selectByCondition(role);
        PageInfo<Role> rolePageInfo = new PageInfo<>(roles);
        Map<String,Object> map = new HashMap<>();
        map.put("sEcho",sEcho);
        map.put("recordsTotal",rolePageInfo.getTotal());
        map.put("recordsFiltered",rolePageInfo.getTotal());
        map.put("data",roles);
        return map;
    }

}
